<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <style type="text/css">
      body{background:#ccc;}
      .main{height:100%; background:#f2f2f2; padding:30px;}
      .main .inp{
        width:100%; height:45px; padding:0px 10px; font-size:15px; border:1px solid #dedede; margin-bottom:20px;
        background:#fff; color:#333; border-radius:3px;
      }
      .main .btn{width:100%; height:45px; background:#62c3d0; color:#fff; font-size:16px; border-radius:3px;}
    </style>
</head>
<body>
  <div id="App" class="main">
    <input type="text" value="" class="inp" id="username" placeholder="用户名">
    <input type="password" value="" class="inp" id="pwd" placeholder="密码">
    <button type="button" class="btn" onclick="login();" tapmode="">登录</button>
  </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript">
    apiready = function(){
      
    };

    function login(){
      var username = $api.trimAll($api.val($api.byId('username')));
      var pwd = $api.trimAll($api.val($api.byId('pwd')));
      if(username.length<1){
        api.toast({msg:'请输入用户名', duration: 1500, location: 'middle'});
        return false;
      }
      if (pwd.length<1) {
        api.toast({msg:'请输入密码', duration: 1500, location: 'middle'});
        return false;
      }
      api.showProgress({
          title: '登录中',
          text: '请稍等...',
      });
      ajax.login('passport/offLineLogin/', {username:username, password:pwd}, function(res){
        var user = res.data;
        $api.setStorage('user',user);

        api.toast({msg:'登录成功', duration: 1500, location: 'middle'});
        setTimeout(function(){
          api.openWin({
              name: 'Set',
              url: 'Set.html',
              pageParam: {name: 'test'}
          });
        }, 1000);
      });
    }

</script>
</html>
